package com.example.module_web.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2018/3/8.
 */

public abstract class BaseFragmentB extends Fragment {
    private RecyclerCom mRecyclerCom;
    private RecyclerView mRecyclerView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(setLayoutId(), container, false);
        initView(view);
        initEvent(getContext(),savedInstanceState);
        setupBaseComponent(getContext(),savedInstanceState);
        return view;
    }

    protected abstract int setLayoutId();
    protected abstract void initView(View view);
    protected abstract void initEvent(Context context, Bundle savedInstanceState);
    protected void setupBaseComponent(Context context, Bundle savedInstanceState){
        if(mRecyclerCom!=null&&mRecyclerView!=null){
            mRecyclerCom.setupRecycler(context,mRecyclerView);
        }
    }

    public RecyclerCom getRecyclerCom() {
        return mRecyclerCom;
    }

    public void setRecyclerCom(RecyclerCom recyclerCom,RecyclerView recyclerView) {
        mRecyclerCom = recyclerCom;
        mRecyclerView = recyclerView;
    }


    public interface RecyclerCom{
        RecyclerView setupRecycler(Context context,RecyclerView view);
    }
}
